load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_binary",
    "drake_cc_library",
)
load(
    "//tools/skylark:drake_py.bzl",
    "drake_py_binary",
    "drake_py_library",
    "drake_py_unittest",
)
load("//tools/skylark:sh.bzl", "sh_binary")

package(default_visibility = ["//visibility:private"])

filegroup(
    name = "demo_data",
    srcs = [
        ":example_scenarios.yaml",
        "//examples/pendulum:models",
        "@drake_models//:iiwa_description",
        "@drake_models//:manipulation_station",
        "@drake_models//:veggies",
        "@drake_models//:wsg_50_description",
    ],
    visibility = ["//:__pkg__"],
)

drake_cc_library(
    name = "scenario",
    srcs = ["scenario.cc"],
    hdrs = ["scenario.h"],
    deps = [
        "//common:name_value",
        "//lcm:drake_lcm_params",
        "//manipulation/kuka_iiwa:iiwa_driver",
        "//manipulation/schunk_wsg:schunk_wsg_driver",
        "//manipulation/util:named_positions_functions",
        "//manipulation/util:zero_force_driver",
        "//multibody/parsing:model_directives",
        "//multibody/plant:multibody_plant_config",
        "//systems/analysis:simulator_config",
        "//systems/sensors:camera_config",
        "//visualization:visualization_config",
    ],
    implementation_deps = [
        "//common/yaml",
    ],
)

drake_cc_binary(
    name = "hardware_sim_cc",
    srcs = ["hardware_sim.cc"],
    deps = [
        ":scenario",
        "//common:add_text_logging_gflags",
        "//manipulation/kuka_iiwa:iiwa_driver_functions",
        "//manipulation/schunk_wsg:schunk_wsg_driver_functions",
        "//manipulation/util:apply_driver_configs",
        "//manipulation/util:named_positions_functions",
        "//manipulation/util:zero_force_driver_functions",
        "//multibody/parsing",
        "//multibody/plant",
        "//systems/analysis:simulator",
        "//systems/analysis:simulator_config_functions",
        "//systems/lcm:lcm_config_functions",
        "//systems/sensors:camera_config_functions",
        "//visualization:visualization_config_functions",
    ],
)

# Binds the C++ hardware_sim program to the data files required for the Demo
# example scenario.
sh_binary(
    name = "demo_cc",
    srcs = [":hardware_sim_cc"],
    args = [
        "--scenario_file=examples/hardware_sim/example_scenarios.yaml",
        "--scenario_name=Demo",
    ],
    data = [
        ":demo_data",
    ],
    # Use the runfiles of the ":demo", not of the ":hardware_sim".
    env = {"RUNFILES_DIR": "../"},
)

drake_py_library(
    name = "hardware_sim_test_common",
    testonly = True,
    srcs = ["test/hardware_sim_test_common.py"],
    deps = [
        "@rules_python//python/runfiles",
    ],
)

drake_py_unittest(
    name = "hardware_sim_cc_test",
    # Note: It's safe to use lcm in the test because it uses a non-default URL
    # and only transmits status messages.
    allow_network = ["lcm:meshcat"],
    data = [
        "test/test_scenarios.yaml",
        ":demo_cc",
    ],
    shard_count = 4,
    deps = [
        ":hardware_sim_test_common",
    ],
)

drake_py_binary(
    name = "hardware_sim_py",
    srcs = ["hardware_sim.py"],
    visibility = [
        "//bindings/pydrake/visualization:__pkg__",
    ],
    deps = [
        "//bindings/pydrake",
    ],
)

# Binds the Python hardware_sim program to the data files required for the Demo
# example scenario.
drake_py_binary(
    name = "demo_py",
    srcs = ["hardware_sim.py"],
    args = [
        "--scenario_file=examples/hardware_sim/example_scenarios.yaml",
        "--scenario_name=Demo",
    ],
    data = [
        ":demo_data",
        ":hardware_sim_py",
    ],
    deps = [
        "//bindings/pydrake",
    ],
)

drake_py_unittest(
    name = "hardware_sim_py_test",
    # Note: It's safe to use lcm in the test because it uses a non-default URL
    # and only transmits status messages.
    allow_network = ["lcm:meshcat"],
    data = [
        "test/test_scenarios.yaml",
        ":demo_py",
    ],
    env = {
        "_DRAKE_DEPRECATION_IS_ERROR": "1",
    },
    shard_count = 4,
    deps = [
        ":hardware_sim_test_common",
    ],
)

drake_py_binary(
    name = "robot_commander",
    srcs = ["robot_commander.py"],
    deps = [
        "//bindings/pydrake",
    ],
)

drake_py_unittest(
    name = "robot_commander_test",
    data = [
        ":example_scenarios.yaml",
    ],
    deps = [
        ":robot_commander",
    ],
)

add_lint_tests(enable_clang_format_lint = False)
